import {reactive,ref} from 'vue';
import {BasicColumn} from '/@/components/Table';
import {FormSchema} from '/@/components/Table';
import {longLimtVal, longLimtValAndNotBlank, rules} from '/@/utils/helper/validator';
import {defHttp} from "@/utils/http/axios";
import {list as listSpecification} from "/@/views/shop/specification/ShSpecification.api";
import {UploadTypeEnum} from "@/components/Form/src/jeecg/components/JUpload";
//列表数据
export const columns: BasicColumn[] = [

   {
    title: '商品名',
    align:"center",
    dataIndex: 'name'
   },
  {
    title: '商品图片',
    align:"center",
    dataIndex: 'pic',
    slots: { customRender: 'imgSlots' },
  },
  {
    title: '价格',
    align:"center",
    dataIndex: 'price'
  },
   {
    title: '商品介绍',
    align:"center",
    dataIndex: 'introduce'
   },
   {
    title: '分类名',
    align:"center",
    dataIndex: 'typeId_dictText'
   },
  {
    title: '供应商',
    align:"center",
    dataIndex: 'supplierId_dictText'
  },
  {
    title: '上架状态',
    align:"center",
    dataIndex: 'status_dictText'
  },
];
//查询数据
export const searchFormSchema: FormSchema[] = [
	{
      label: "商品名",
      field: 'name',
      component: 'JInput',
      //colProps: {span: 6},
 	},
  {
    label: '分类名',
    field: 'typeId',
    component: 'JTreeSelect',
    componentProps: (formModel)=>{
      return {
        dict: "sh_commodity_type,name,id",
        pidField: 'parent_id',
      }
    },
  },
];
//表单数据


export const formSchema: FormSchema[] = [
  {
    label: '商品名',
    field: 'name',
    component: 'Input',
    dynamicRules: ({model,schema}) => {
          return [
                 { required: true,validator: (_, value) => {
                     return longLimtValAndNotBlank(value,16)
                   }},
          ];
     },
  },
  {
    label: '商品介绍',
    field: 'introduce',
    component: 'Input',
    dynamicRules: ({model,schema}) => {
      return [
        { required: false,validator: (_, value) => {
            return longLimtVal(value,1500)
          }},
      ];
    },
  },
  {
    label: '商品图片',
    field: 'pic',
    component: 'JUpload',
    componentProps: {
      bizPath: 'shop',
      fileType: UploadTypeEnum.image,
      maxCount: 1,
    },
  },
  {
    label: '价格',
    field: 'price',
    component: 'InputNumber',
    dynamicRules: ({model,schema}) => {
      return [
        { required: false,validator: (_, value) => {
            return longLimtValAndNotBlank(value,10)
          }},
      ];
    },
  },
  {
    label: '分类名',
    field: 'typeId',
    component: 'JSearchSelect',
    componentProps: (formModel)=>{
      return {
        dict: "sh_commodity_type,name,id",
      }
    },
    required:true,
  },
  {
    label: '供应商',
    field: 'supplierId',
    component: 'JSearchSelect',
    componentProps: (formModel) => {
      return {
        dict: "sh_supplier,name,id",
      }
    }
  },
  {
    label: '状态',
    field: 'status',
    component: 'JDictSelectTag',
    componentProps:{
      dictCode:"commodity_status",
      stringToNumber:true,
    },
    required:true,
  },
	// TODO 主键隐藏字段，目前写死为ID
	{
	  label: '',
	  field: 'id',
	  component: 'Input',
	  show: false
	},
];

// 高级查询数据
export const superQuerySchema = {
  name: {title: '商品名',order: 0,view: 'text', type: 'string',},
  introduce: {title: '商品介绍',order: 1,view: 'text', type: 'string',},
  typeId: {title: '分类id',order: 2,view: 'text', type: 'string',},
};

/**
* 流程表单调用这个方法获取formSchema
* @param param
*/
export function getBpmFormSchema(_formData): FormSchema[]{
  // 默认和原始表单保持一致 如果流程中配置了权限数据，这里需要单独处理formSchema
  return formSchema;
}
